package me.zhengjie.modules.workflow.commad;

import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.VariableInstanceEntity;
import org.activiti.engine.impl.persistence.entity.VariableInstanceEntityManager;
import org.activiti.engine.task.Task;

import java.util.List;

/**
 * 执行变量删除命令
 *
 * @description: FlowToPreNodeCmd <br>
 * @date: 2021/5/12 18:06 <br>
 * @author: wangz <br>
 * @version: 1.0 <br>
 */
public class ExecutionVariableDeleteCmd implements Command<String> {

    /**
     * 执行流执行id
     **/
    private String executionId;

    public ExecutionVariableDeleteCmd(String executionId) {
        this.executionId = executionId;
    }

    @Override
    public String execute(CommandContext commandContext) {
        //任务变量删除
        VariableInstanceEntityManager vm = commandContext.getVariableInstanceEntityManager();
        List<VariableInstanceEntity> vs = vm.findVariableInstancesByExecutionId(this.executionId);
        for (VariableInstanceEntity v : vs) {
            vm.delete(v);
        }
        return executionId;
    }
}
